<script setup lang="ts">
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import entryLayout from './layouts/entry/index.vue'
import defaultLayout from './layouts/default/index.vue'

const route = useRoute()

const layoutComponent = computed(() => {
  const { matched } = route
  if (matched.length) {
    const [pageLayout] = [...matched]
      .reverse()
      .map(_ => _.meta.layout)
      .filter(_ => _)
    if (pageLayout) {
      return pageLayout === 'entry' ? entryLayout : pageLayout
    }
    return defaultLayout
  }
  return null
})
</script>

<template>
  <ElConfigProvider :locale="zhCn">
    <component :is="layoutComponent" />
  </ElConfigProvider>
</template>
